package com.modules.controller.sys;


import com.common.controller.BaseController;
import com.common.vo.LoginUser;
import com.common.vo.Result;
import com.modules.entity.sys.MenuEntity;
import com.modules.service.sys.MenuService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * menus控制层
 * @author yyq
 *
 */
@Controller
@RequestMapping("/sys/menu")
public class MenusController extends BaseController<MenuEntity>{
	
	@Resource
	private MenuService menuService;

	@GetMapping(value="/")
	public ModelAndView index(){
		return new ModelAndView("/sys/menu");
	}
	
	/**
	 * 查询
	 * @return
	 */
	@GetMapping("/select")
	@ResponseBody
	public Result<?> select(MenuEntity menu){
		return menuService.select(getPage(), menu);
	}
	
	/**
	 * 查询树形表格
	 * @return
	 */
	@GetMapping("/selectTreeTable")
	@ResponseBody
	public Result<?> selecTreeTable(MenuEntity menu){
		return menuService.selecTreeTable(menu);
	}
	
	/**
	 * 保存
	 * @return
	 */
	@PostMapping("/save")
	@ResponseBody
	public Result<?> save(@Valid MenuEntity menu){
		return menuService.saveMenu(menu);
	}
	
	/**
	 * 删除
	 * @return
	 */
	@DeleteMapping("/delete")
	@ResponseBody
	public Result<?> delete(MenuEntity menu){
		return menuService.delete(menu.getMid());
	}
	
	/**
	 * 更改状态
	 * @return
	 */
	@PostMapping("/updateState")
	@ResponseBody
	public Result<?> updateState(MenuEntity menu){
		return menuService.updateState(menu);
	}
	
	/**
	 * 获取左侧菜单
	 * @return
	 */
	@PostMapping("/selectTree")
	@ResponseBody
	public Result<?> selectTree(){
		LoginUser user = getUser();
		return menuService.selectTree(user.getRid());
	} 
	
	/**
	 * 获取左侧菜单所有
	 * @return
	 */
	@GetMapping("/selectTreeAll")
	@ResponseBody
	public Result<?> selectTreeAll(){
		return menuService.selectTreeAll();
	} 
	
	/**
	 * 菜单选择角色
	 * @return
	 */
	@GetMapping("/selectMenuRole")
	@ResponseBody
	public Result<?> selectMenuRole(String mid){
		return menuService.selectMenuRole(mid);
	} 
	
	/**
	 * 保存菜单选择角色
	 * @return
	 */
	@PostMapping("/saveMenuRole")
	@ResponseBody
	public Result<?> saveMenuRole(String[] rids, Integer mid){
		return menuService.saveMenuRole(rids, mid, getUser().getLastOid());
	} 


}